package com.example.base.system.domain;

import com.alibaba.fastjson.annotation.JSONField;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.example.base.system.service.SysTableColumnService;
import com.example.base.utils.SpringContextUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 
 * </p>
 *
 * @author X.I.O
 * @since 2024-02-21
 */

@Data
@ApiModel(description = "")
@TableName("sys_table")
public class SysTable implements Serializable {

    private static final long serialVersionUID = 1L;

    @TableId(value="id", type= IdType.AUTO)
    @ApiModelProperty(value = "")
    private Integer id;
    /**
    * 名称
    */
    @ApiModelProperty(value = "名称")
    private String tableName;
    /**
    * 标识
    */
    @ApiModelProperty(value = "标识")
    private String tableNo;
    /**
    * 关联的表名
    */
    @ApiModelProperty(value = "关联的表名")
    private String tableTable;
    /**
    * 创建时间
    */
    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(value = "创建时间")
    private Date createtime;
    /**
    * 更新时间
    */
    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(value = "更新时间")
    private Date updatetime;

    @TableField(exist = false)
    private List<SysTableColumn> columns;

    public List<SysTableColumn> getColumns() {
        if(this.id!=null){
            SysTableColumnService service=SpringContextUtils.getBean(SysTableColumnService.class);
            List<SysTableColumn> sysTableColumns=service.getSysTableColumnByTableId(this.id);
            this.columns=sysTableColumns;
        }
        return columns;
    }
}
